package com.atguigu.gulimail.search.controller;

import com.atguigu.gulimail.search.service.MailSearchService;
import com.atguigu.gulimail.search.vo.SearchParam;
import com.atguigu.gulimail.search.vo.SearchResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author Guo 2022/11/1 19:53:10
 */
@Controller
@Slf4j
public class SearchController {

    @Resource
    MailSearchService mailSearchService;

    /**
     * 自动将页面提交过来的所有请求查询参数封装成指定的对象
     *
     * @param param
     * @return
     */
    @GetMapping("/list.html")
    public String listPage(SearchParam param, Model model) throws IOException {

        // 通过传递来的检索参数，去ES中检索查询商品
        SearchResult result = mailSearchService.search(param);
        model.addAttribute("result", result);

//        log.info(String.valueOf(result));
        // 返回的list对应在resources中templates里的list.html
        return "list";
    }

    public static String test1() {
        System.out.println("开始测试");
        try {
            int i = 1;
            try {
                int ii = 1/0;
            }catch (Exception e) {
                System.out.println("报错啦");
                throw new Exception("报错啦111");
            }finally {
                System.out.println("111");
            }

        } catch (Exception e) {
            System.out.println("走我了吗？？");
            log.error(e.getMessage());
        } finally {
            System.out.println("我被执行了" + 2/3);
            System.out.println("lalala");
        }
        return "成功执行完毕";
    }

    public static void main(String[] args) {
        System.out.println(test1());
    }

}
